package com.gitee.cashzhang27.test.boot.other.intercept;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author cash Zhang
 * @since 2019/02/18 16:21
 */
public class AdminLoginIntercept implements HandlerInterceptor {

  /**
   * 进入controller层之前拦截请求
   */
  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
      Object handler) {
    // 如果已经登录返回true。
    // 如果没有登录没有登录，可以使用 reponse.send() 跳转页面。后面要跟return false,否则无法结束;

    // 为了测试，打印一句话
    System.out.println("1。");

    return true;
  }

  /**
   * 处理请求完成后视图渲染之前的处理操作
   */
  @Override
  public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
      ModelAndView modelAndView) {
    System.out.println("2。");
  }

  /**
   * 视图渲染之后操作
   */
  @Override
  public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
      Object handler, Exception ex) {
    System.out.println("3。");
  }
}
